package com.wangzaiplus.test.juc.thread;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName ThreadGroupDemo
 * @Description: TODO
 * @Author wgc
 * @Date 2020/06/28 11:20
 * @Version V1.0
 **/
public class ThreadGroupDemo {


    public  static class R1 implements  Runnable{

        @Override
        public void run() {
            System.out.println("threadName:"+Thread.currentThread().getName());

            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) throws InterruptedException {
            ThreadGroup threadGroup=new ThreadGroup("thread-group-1");

            Thread t1=new Thread(threadGroup,new R1(),"t1");
             Thread t2=new Thread(threadGroup,new R1(),"t2");
             t1.start();
             t2.start();
        Thread t3=new Thread(threadGroup,new R1(),"t3");
        TimeUnit.SECONDS.sleep(1);
        System.out.println("活动线程数:"+ threadGroup.activeCount());
        System.out.println("活动线程组:"+ threadGroup.activeGroupCount());
        System.out.println("线程组名称:"+ threadGroup.getName());
    }
}
